﻿using System;
using System.Web;
using System.Web.DynamicData;
using System.Web.Optimization;
using System.Web.Routing;
using Altairis.FluffyCloud.Data;

namespace Altairis.FluffyCloud.WebCore {

    public class Global : HttpApplication {
#if DEBUG
        private const string BUILD = "debug";
#else
        private const string BUILD = "release";
#endif
        private const string FORMAT_VERSION_ID = "Web: {0:4}, DB: {1:4}, {2} build";

        public static string VersionString { get; private set; }

        private void Application_Start(object sender, EventArgs e) {
            // Version
            var webVersion = System.Reflection.Assembly.GetAssembly(typeof(Global)).GetName().Version;
            var dbVersion = System.Reflection.Assembly.GetAssembly(typeof(Altairis.FluffyCloud.Data.FluffyDbContext)).GetName().Version;
            VersionString = string.Format(FORMAT_VERSION_ID,
                webVersion,                     // 0
                dbVersion,                      // 1
                BUILD);                         // 2

            // Register model for Dynamic Data
            var metaModel = new MetaModel();
            metaModel.RegisterContext(typeof(FluffyBindingContext));

            // Register assets
            BundleConfig.RegisterBundles(BundleTable.Bundles);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
        }
    }
}